package com.hangyixing.decode.service.common;

import com.hangyixing.decode.entity.Time;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * class note ：
 *
 * @author
 * @version 1.0.0
 * @date 2020/3/16 0016 20:12
 */


public class DecodeTime {


    public  static  String  decodeMonth(String monthAndDay){
        String day = monthAndDay.substring(0,2);
        String month = monthAndDay.substring(2,monthAndDay.length());
        if(month.equals("JAN")){
            monthAndDay = "1-"+day;
        }
        if(month.equals("FEB")){
            monthAndDay = "2-"+day;
        }
        if(month.equals("MAR")){
            monthAndDay = "3-"+day;
        }
        if(month.equals("APR")){
            monthAndDay = "4-"+day;
        }
        if(month.equals("MAY")){
            monthAndDay = "5-"+day;
        }
        if(month.equals("JUN")){
            monthAndDay = "6-"+day;
        }
        if(month.equals("JUL")){
            monthAndDay = "7-"+day;
        }

        if(month.equals("AUG")){
            monthAndDay = "8-"+day;
        }
        if(month.equals("SEP")){
            monthAndDay = "9-"+day;
        }

        if(month.equals("OCT")){
            monthAndDay = "10-"+day;
        }
        if(month.equals("NOV")){
            monthAndDay = "11-"+day;
        }
        if(month.equals("DEC")){
            monthAndDay = "12-"+day;
        }

        return monthAndDay;
    }
    public  static Time decodeTime(String time, String monthAndDay ) throws ParseException {
        //time="193439U";
        Time time1 = new Time();
        String hour = time.substring(0, 2);
        String minute = time.substring(2, 4);
        String second = time.substring(4, 6);

        if (time.substring(6, 7).equals("L")) {
            time= hour + ":" + minute + ":" + second;
            time = monthAndDay+" "+time;
        }
        if (time.substring(6, 7).equals("U")) {
            time= hour + ":" + minute + ":" + second;
            time = UTCToCST("2020-"+monthAndDay+" "+time, "yyyy-MM-dd HH:mm:ss");
            time = time.substring(5,time.length());
        }
        String[] n = time.split(" ");
        time1.setMonthAndDay(n[0]);
        time1.setTime(n[1]);
        return time1;
    }

        public static String UTCToCST(String UTCStr, String format) throws ParseException {
            Date date = null;
            SimpleDateFormat sdf = new SimpleDateFormat(format);
            date = sdf.parse(UTCStr);
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            calendar.set(Calendar.HOUR, calendar.get(Calendar.HOUR) + 8);
            return sdf.format(calendar.getTime());
        }

    }















